import { isArray, isNumber, isObject, isString } from "../../utils";

export function renderList(source, renderItem) {
    // v-for的写法
    // item in arr
    // item in obj
    // item in 10
    // item in 'abcde'
    // 判断类型
    const nodes = []
    if (isNumber(source)) {
        for (let i = 0; i < source; i++) {
            nodes.push(renderItem(i + 1, i))
        }
    } else if (isString(source) || isArray(source)) {
        for (let i = 0; i < source.length; i++) {
            nodes.push(renderItem(source[i], i))
        }
    } else if (isObject(source)) {
        const keys = Object.keys()
        keys.forEach((key, index) => {
            nodes.push(renderItem(source[key], key, index))
        })
    }
    return nodes
}